package com.ktjy.web.dao.impl;

import com.ktjy.web.dao.AttrValuesDao;
import com.ktjy.web.dao.BannerItemDao;
import com.ktjy.web.dao.BaseDao;
import com.ktjy.web.entity.AttrValues;
import com.ktjy.web.entity.BannerItem;
import com.ktjy.web.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.sql.SQLException;
import java.util.List;

/**
 * 轮播图模块DAO接口实现类
 * @version v1.0
 * @Author 郴州科泰
 * @Create 2024-07-17 - 16:57
 */
public class BannerItemDaoImpl extends BaseDao implements BannerItemDao {
    @Override
    public List<BannerItem> findByType(int type) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<BannerItem> list=null;
        try{
            list=sqlSession.getMapper(BannerItemDao.class).findByType(type);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return list;
    }

    @Override
    public BannerItem findById(int id) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        BannerItem bannerItem=null;
        try{
            bannerItem=sqlSession.getMapper(BannerItemDao.class).findById(id);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return bannerItem;
    }

    @Override
    public List<BannerItem> selectAll() {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<BannerItem> list=null;
        try{
            list=sqlSession.getMapper(BannerItemDao.class).selectAll();

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return list;
    }

    @Override
    public BannerItem selectById(int id) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        BannerItem bannerItem=null;
        try{
            bannerItem=sqlSession.getMapper(BannerItemDao.class).selectById(id);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return bannerItem;
    }

    @Override
    public int deleteById(int id) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        int count=0;
        try{
            count=sqlSession.getMapper(BannerItemDao.class).deleteById(id);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return count;
    }

    @Override
    public List<BannerItem> page(int type, int pageNo, int pageSize) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        List<BannerItem> list=null;
        try{
            list=sqlSession.getMapper(BannerItemDao.class).page(type,pageNo,pageSize);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return list;
    }

    @Override
    public int count() {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        int count=0;
        try{
            count=sqlSession.getMapper(BannerItemDao.class).count();

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return count;
    }

    @Override
    public int update(BannerItem bannerItem) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        int count=0;
        try{
            count=sqlSession.getMapper(BannerItemDao.class).update(bannerItem);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return count;
    }

    @Override
    public int insert(BannerItem bannerItem) {
        SqlSession sqlSession= MyBatisUtil.createSqlSession();
        int count=0;
        try{
            count=sqlSession.getMapper(BannerItemDao.class).insert(bannerItem);

        }finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }

        return count;
    }
    /**
     * 根据跳转类型获取轮播图数据列表数据
     * @param type 跳转类型
     * @return 获取到的轮播图数据列表数据
     */


}
